#ifndef ITEM_H
#define ITEM_H

#include <QObject>

#include <QVector>
#include <QString>

class QUrl;

class NameSpace;
class UniqueName;
class List;
class Source;

class Item : public QObject
{
    Q_OBJECT

public:
    typedef QVector<Source*> t_sources;

public:
    explicit Item(
        NameSpace *nameSpace
    ,   const QString &name);
    virtual ~Item();

    const t_sources sources() const;

    NameSpace *nameSpace();


    void setName(const QString &name);
    const QString name() const;

    void setQuantity(const uint quantity);
    const uint quantity() const;

    void setIgnored(const bool ignored);
    const bool ignored() const;


    Source *source(const QString &name);

    void addSource(Source *source);
    void removeSource(Source *source);

    const bool isUpdating() const;

signals:
    void modified();
    void updated(
        uint succeeded
    ,   uint failed);

    void nameChanged(QString name);
    void quantityChanged(uint quantity);
    void ignoreStateChanged(bool ignored);

    void sourceAdded(Source *source);
    void sourceRemoved(Source *source);

    void sourceIgnoreStateChanged(bool ignored);

public slots:
    void update();
    void cancel();

protected slots:
    void source_updated(bool succeeded);
    void source_canceled();

protected:
    NameSpace *m_nameSpace;

    bool m_ignored;

    UniqueName *m_name;
    uint m_quantity;

    t_sources m_sources;

    uint m_succeeded;
    uint m_failed;
};

#endif // ITEM_H
